local fuji = fk.CreateSkill {

  name = "joy__fuji",

  tags = { Skill.Compulsory, },

}



fuji:addEffect(fk.CardUsing, {
  name = "joy__fuji",
  anim_type = "offensive",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(fuji.name) and
      (data.card.trueName == "slash" or data.card:isCommonTrick()) and
      table.find(player.room:getOtherPlayers(player), function(p) return p:distanceTo(player) < 3 end)
  end,
  on_use = function(self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function(p) return p:distanceTo(player) <3 end)
    if #targets > 0 then
      data.disresponsiveList = data.disresponsiveList or {}
      for _, p in ipairs(targets) do
        table.insertIfNeed(data.disresponsiveList, p.id)
      end
    end
  end,
})

fuji:addEffect(fk.Damaged, {
  name = "#joy__fuji_mark",
  anim_type = "offensive",
  mute = true,
  events = {fk.Damaged},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
      return target ~= player and data.from == player and player:hasSkill(fuji.name) and not target.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      room:addPlayerMark(target, "@@joyfuji")
      room:addPlayerMark(target, MarkEnum.UncompulsoryInvalidity)
  end,
})
fuji:addEffect(fk.TurnStart, {
  refresh_events = { fk.TurnStart },
  can_refresh = function(self, event, target, player, data)
      return target ~= Player 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if p:getMark("@@joyfuji") > 0 then
        room:removePlayerMark(p, "@@joyfuji")
        room:removePlayerMark(p,MarkEnum.UncompulsoryInvalidity)
      end
    end
  end,
})

return fuji